package com.jdy.haoduoaiteacher.adapter;//package com.jdy.haoduoaiteacher.adapter;
//
//import java.util.ArrayList;
//import java.util.HashMap;
//
//import org.json.JSONException;
//import org.json.JSONObject;
//
////import rx.functions.Action0;
////import rx.functions.Action1;
////import rx.functions.Func0;
////import rx.functions.Func1;
//import android.annotation.SuppressLint;
//import android.app.Activity;
//import android.content.DialogInterface;
//import android.content.Intent;
//import android.graphics.drawable.Drawable;
//import android.os.Bundle;
//import android.os.Message;
//import android.util.TypedValue;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.View.OnClickListener;
//import android.view.ViewGroup;
//import android.widget.BaseAdapter;
//import android.widget.Button;
//import android.widget.ImageView;
//import android.widget.ListView;
//import android.widget.ProgressBar;
//import android.widget.TextView;
//
//import com.jdy.haoduoaiteacher.MyTeacherApp;
//import com.jdy.haoduoaiteacher.R;
//import com.jdy.haoduoaiteacher.activity.AddHabitClockActivity;
//import com.jdy.haoduoaiteacher.activity.BaseActivity;
//import com.jdy.haoduoaiteacher.activity.MyPainPointSelectActivity;
//import com.jdy.haoduoaiteacher.activity.PainPointDiscussionActivity;
//import com.jdy.haoduoaiteacher.fragment.TabIndexFragment;
//import com.jdy.haoduoaiteacher.intface.IAsyncTask;
//import com.jdy.haoduoaiteacher.model.HabitMedia;
//import com.jdy.haoduoaiteacher.model.HabitPlan;
//import com.jdy.haoduoaiteacher.model.LeHotDynamicItemWrapper;
//import com.jdy.haoduoaiteacher.model.LeUser;
//import com.jdy.haoduoaiteacher.model.PainPointItem;
//import com.jdy.haoduoaiteacher.parse.JsonSerializer;
//import com.jdy.haoduoaiteacher.util.CommonUtil;
//import com.jdy.haoduoaiteacher.util.CustomAsyncTask;
//import com.jdy.haoduoaiteacher.util.HttpUtils;
////import com.jdy.haoduoaiteacher.util.ImHelper;
//import com.jdy.haoduoaiteacher.util.ResponseResult;
//import com.jdy.haoduoaiteacher.util.Tools;
//import com.jdy.haoduoaiteacher.widget.CustomTimeDialog;
//import com.jdy.haoduoaiteacher.widget.CustomTimeDialog.Builder.OnOkClickListener;
//import com.squareup.picasso.Picasso;
//
//import static android.R.attr.id;
//
///**
// * 习惯养成
// *
// * @author hf
// *
// */
//@SuppressLint("InflateParams")
//public class HabitPlanAdapter extends BaseAdapter {
//  private BaseActivity mContext;
//  private ArrayList<HabitPlan> mList;
//  private LayoutInflater mInflater;
//  private HabitMedia mHabitMusic;
//  private OnSetAlarmListener mOnSetAlarmListener;
//  private CustomTimeDialog timeDlg;
//
//  public OnSetAlarmListener getOnSetAlarmListener() {
//    return mOnSetAlarmListener;
//  }
//
//  public void updatePlayingInfo(HabitMedia hm) {
//    mHabitMusic = hm;
//    notifyDataSetChanged();
//  }
//
//  // public void updatedata(ArrayList<HabitPlan> list) {
//  // mList = list;
//  // }
//
//  public void setOnSetAlarmListener(OnSetAlarmListener mmOnSetAlarmListener) {
//    this.mOnSetAlarmListener = mmOnSetAlarmListener;
//  }
//
//  public interface OnSetAlarmListener {
//    void finishSetAlarm();
//  }
//
//  public void setData(ArrayList<HabitPlan> list) {
//    mList = list;
//  }
//
//  public HabitPlanAdapter(BaseActivity context, ArrayList<HabitPlan> list,
//      ListView lll) {
//    this.mContext = context;
//    this.mList = list;
//    mInflater = LayoutInflater.from(mContext);
//  }
//
//  @Override
//  public int getCount() {
//    return mList.size();
//  }
//
//  @Override
//  public Object getItem(int position) {
//    return mList.get(position);
//  }
//
//  @Override
//  public long getItemId(int position) {
//    return position;
//  }
//
//  private void setHabitTime(final HabitPlan iitem) {
//    CustomTimeDialog.Builder customBuilder = new CustomTimeDialog.Builder(
//        mContext);
//    customBuilder.setTitle("设置每次启动时间")
//        .setNegativeButton("取消", new DialogInterface.OnClickListener() {
//          @Override
//          public void onClick(DialogInterface dialog, int which) {
//            dialog.dismiss();
//          }
//        }).setPositiveButton("确定", new OnOkClickListener() {
//          @Override
//          public void onClickOk(final int hourOfDay, final int minute) {
//            timeDlg.dismiss();
//
//
//
//            new CustomAsyncTask(mContext, new IAsyncTask() {
//              @Override
//              public void onRecieveData(Activity activity,
//                                        ResponseResult result) {
//                if (result.isSuccess()) {
//                  if (mOnSetAlarmListener != null && result.isSuccess()) {
//                    mOnSetAlarmListener.finishSetAlarm();
//                  }
//                }
//              }
//
//              @Override
//              public ResponseResult doInbackground(Activity activity) {
//                LeUser lu = MyTeacherApp.getInstance().getUser();
//                if (lu == null) {
//                  lu = Tools.restoreLeUser();
//                }
//
//                HashMap<String, Object> param_ = new HashMap<String, Object>();
//                param_.put(HttpUtils.TAG_SNO_I, lu.sno);
//                param_.put(HttpUtils.TAG_KEY_I, HttpUtils.KEY);
//                param_.put("time", String.format("%02d", hourOfDay) + ":"
//                        + String.format("%02d", minute));
//
//                return HttpUtils.startRequest(HttpUtils.API_URL
//                                + "/api/2.0/operation/habit/habits_teacher/" + iitem.id, param_,
//                        HttpUtils.TAG_PUT_REQUEST);
//              }
//            }).execute();
//          }
//        });
//
//    if (!mContext.isFinishing()) {
//      timeDlg = customBuilder.create();
//      timeDlg.show();
//    }
//  }
//
//  @Override
//  public View getView(int position, View convertView, ViewGroup parent) {
//    final HabitPlan item = mList.get(position);
//    final ViewHolder holder;
//    if (convertView == null) {
//      convertView = mInflater.inflate(R.layout.story_item, null);
//      holder = new ViewHolder();
//      holder.pb_day = (ProgressBar) convertView.findViewById(R.id.pb_day);
//      holder.tv_label = (TextView) convertView.findViewById(R.id.tv_label);
//      holder.tv_insistdays = (TextView) convertView
//          .findViewById(R.id.tv_insistdays);
//      holder.tv_morningsong = (TextView) convertView
//          .findViewById(R.id.tv_morningsong);
//      holder.tv_clock = (TextView) convertView.findViewById(R.id.tv_clock);
//      holder.bg = (Button) convertView.findViewById(R.id.bg);
////      holder.img_palyorpause = (ImageView) convertView
////          .findViewById(R.id.img_palyorpause);
//      holder.slayout = convertView.findViewById(R.id.slayout);
//     // holder.img_palyorpause.setTag(false);
//      holder.img = (ImageView) convertView.findViewById(R.id.img);
//      convertView.setTag(holder);
//    } else {
//      holder = (ViewHolder) convertView.getTag();
//    }
//
//    holder.pb_day.setMax(10 * 21);
//
//    Drawable drawable2 = mContext.getResources().getDrawable(R.drawable.clock);
//
//    if (item != null) {
//      holder.tv_morningsong.setText(item.name);
//      int lastIdx = item.time.lastIndexOf(":");
//      holder.tv_clock.setText(item.time.substring(0, lastIdx));
//
//      Drawable drawable = mContext.getResources().getDrawable(
//          R.drawable.edit_habit);
//
//      if (TabIndexFragment.allowEditTime >= 0) {
//        drawable = mContext.getResources().getDrawable(R.drawable.edit_habit);
//      } else if (TabIndexFragment.allowEditTime < 0) {
//        drawable = mContext.getResources().getDrawable(
//            R.drawable.edit_habit_disable);
//      }
//
//      drawable.setBounds(0, 0, drawable.getMinimumWidth(),
//          drawable.getMinimumHeight());
//      drawable2.setBounds(0, 0, drawable2.getMinimumWidth(),
//          drawable2.getMinimumHeight());
//      holder.tv_clock.setTag(false);
//      holder.tv_clock.setCompoundDrawables(drawable2, null, drawable, null);
//      holder.tv_clock.setOnClickListener(new View.OnClickListener() {
//        @Override
//        public void onClick(View v) {
//          boolean clockTag = (boolean) holder.tv_clock.getTag();
//          if (TabIndexFragment.allowEditTime >= 0 && !clockTag) {
//            if (item.is_customized == 1) {
//              setHabitTime(item);
//            } else {
//              setHabitTime(item);
//            }
//          }
//        }
//      });
//
//  //    holder.img_palyorpause.setOnTouchListener(CommonUtil.VIEW_TOUCH_DARK);
//
//      holder.tv_insistdays.setText("已坚持" + item.day + "天");
//
//      holder.pb_day.setProgress(10 * item.day);
//
//      if (Tools.isNotEmpty(item.img)) {
//        if (Tools.isEmpty(holder.img.getTag())) {
//          Picasso.with(mContext).load(item.img).into(holder.img);
//          holder.img.setTag(item.img);
//        } else {
//          if (item.img.equals(holder.img.getTag())) {
//            // TODO
//          } else {
//            Picasso.with(mContext).load(item.img).into(holder.img);
//            holder.img.setTag(item.img);
//          }
//        }
//      }
//
//      if (item.status == 1) {
//        holder.bg.setText("已执行");
//        holder.bg.setTextSize(TypedValue.COMPLEX_UNIT_SP, 11);
//      } else {
//        holder.bg.setText("未执行");
//        holder.bg.setTextSize(TypedValue.COMPLEX_UNIT_SP, 11);
//      }
//
//      holder.slayout.setOnClickListener(new OnClickListener() {
//        @Override
//        public void onClick(View v) {
//          Intent intent = new Intent();
//          intent.setClass(mContext, AddHabitClockActivity.class);
//          intent.putExtra("isedit", true);
//
//          PainPointItem item2 = new PainPointItem();
//          item2.id = item.id;
//          item2.img = item.img;
//          item2.name = item.name;
//          item2.time = item.time;
//          item2.enable = 1;
//          item2.macid = item.macid;
//          item2.mp3_url = item.mp3_url;
//
//          intent.putExtra("custompainpoint", item2);
//          mContext.startActivity(intent);
//        }
//      });
//    }
//
//   // holder.img_palyorpause.setClickable(true);
//
////    if (mHabitMusic != null) {
////      if (mHabitMusic.is_customized == 1 && item.is_customized == 1
////              || mHabitMusic.is_customized == 0 && item.is_customized == 0 ) {
////          // 自定义习惯
////
////      } else if () {
////        if ( && ) {
////
////        }
////      }
////    }
//
//
//
//
////    if (mHabitMusic != null && mHabitMusic.id == item.id && item.is_customized == 1
////            || mHabitMusic != null && mHabitMusic.id == item.id && item.is_customized != 1) {
//
//
//    if (mHabitMusic != null && mHabitMusic.id == item.id && mHabitMusic.is_customized == item.is_customized) {
//    //  holder.img_palyorpause.setVisibility(View.VISIBLE);
//      if (item.status == 1) {
//        holder.bg.setText("已执行");
//        holder.bg.setTextSize(TypedValue.COMPLEX_UNIT_SP, 11);
////        holder.img_palyorpause.setClickable(false);
////        holder.img_palyorpause.setBackgroundResource(R.drawable.play_gray);
//
//        if (Tools.isNotEmpty(mHabitMusic.playtime)
//            && (mHabitMusic.playtime.contains("已执行") || mHabitMusic.playtime
//                .contains("已完成"))) {
//          holder.bg.setTextSize(TypedValue.COMPLEX_UNIT_SP, 11);
//          holder.bg.setText("已执行");
//          holder.bg.setTextSize(TypedValue.COMPLEX_UNIT_SP, 11);
////          holder.img_palyorpause.setClickable(false);
////          holder.img_palyorpause.setBackgroundResource(R.drawable.play_gray);
//
//          Drawable drawable = mContext.getResources().getDrawable(
//              R.drawable.edit_habit);
//          drawable.setBounds(0, 0, drawable.getMinimumWidth(),
//              drawable.getMinimumHeight());
//          holder.tv_clock.setCompoundDrawables(drawable2, null, drawable, null);
//          holder.tv_clock.setTag(false);
//        } else {
//          holder.bg.setTextSize(TypedValue.COMPLEX_UNIT_SP, 7);
//          holder.bg.setText(mHabitMusic.playtime);
//        }
//
//        if (Tools.isNotEmpty(mHabitMusic.playstatus)) {
//          if (Tools.isNotEmpty(mHabitMusic.playstatus)
//              && mHabitMusic.playstatus.contains("playing")) {
//          //  holder.img_palyorpause.setBackgroundResource(R.drawable.pause_blue);
//          } else {
//           // holder.img_palyorpause.setBackgroundResource(R.drawable.play_blue);
//          }
//
//          Drawable drawable = mContext.getResources().getDrawable(
//              R.drawable.edit_habit_disable);
//          drawable.setBounds(0, 0, drawable.getMinimumWidth(),
//              drawable.getMinimumHeight());
//          holder.tv_clock.setCompoundDrawables(drawable2, null, drawable, null);
//          holder.tv_clock.setTag(true);
//        }
//
//        if (Tools.isNotEmpty(mHabitMusic.playtime)
//            && (mHabitMusic.playtime.contains("已执行") || mHabitMusic.playtime
//                .contains("已完成"))) {
//          holder.bg.setTextSize(TypedValue.COMPLEX_UNIT_SP, 11);
//          holder.bg.setText("已执行");
//          holder.bg.setTextSize(TypedValue.COMPLEX_UNIT_SP, 11);
////          holder.img_palyorpause.setClickable(false);
////          holder.img_palyorpause.setBackgroundResource(R.drawable.play_gray);
//
//          Drawable drawable = mContext.getResources().getDrawable(
//              R.drawable.edit_habit);
//          drawable.setBounds(0, 0, drawable.getMinimumWidth(),
//              drawable.getMinimumHeight());
//          holder.tv_clock.setCompoundDrawables(drawable2, null, drawable, null);
//          holder.tv_clock.setTag(false);
//        }
//
////        holder.img_palyorpause.setOnClickListener(new View.OnClickListener() {
////          @Override
////          public void onClick(View v) {
////            ImHelper mImHelper = MyTeacherApp.getInstance().getImHelper();
////            if (mImHelper != null && mImHelper.isLogin()) {
////              if (Tools.isNotEmpty(mHabitMusic.playstatus)
////                  && mHabitMusic.playstatus.contains("playing")) {
////                JSONObject jsonObject = new JSONObject();
////                try {
////                  jsonObject.put("code", "app");
////                  jsonObject.put("act", "habit_pause");
////                  jsonObject.put("data", "");
////                  mImHelper.send(jsonObject.toString());
////                } catch (JSONException e) {
////                  e.printStackTrace();
////                }
////              } else {
////                JSONObject jsonObject = new JSONObject();
////                try {
////                  jsonObject.put("code", "app");
////                  jsonObject.put("act", "habit_start");
////                  jsonObject.put("data", "");
////                  mImHelper.send(jsonObject.toString());
////                } catch (JSONException e) {
////                  e.printStackTrace();
////                }
////              }
////            }
////          }
////        });
//      } else {
//        holder.bg.setText(mHabitMusic.playtime);
//        if (Tools.isNotEmpty(mHabitMusic.playtime)
//            && (mHabitMusic.playtime.contains("已执行") || mHabitMusic.playtime
//                .contains("已完成"))) {
//          holder.bg.setTextSize(TypedValue.COMPLEX_UNIT_SP, 11);
//          holder.bg.setText("已执行");
//        } else {
//          holder.bg.setTextSize(TypedValue.COMPLEX_UNIT_SP, 7);
//        }
//
//        if (Tools.isNotEmpty(mHabitMusic.playstatus)) {
//          if (Tools.isNotEmpty(mHabitMusic.playstatus)
//              && mHabitMusic.playstatus.contains("playing")) {
//            // 播放中
//          //  holder.img_palyorpause.setBackgroundResource(R.drawable.pause_blue);
//          } else {
//            // 暂停
//          //  holder.img_palyorpause.setBackgroundResource(R.drawable.play_blue);
//          }
//
//          Drawable drawable = mContext.getResources().getDrawable(
//              R.drawable.edit_habit_disable);
//          drawable.setBounds(0, 0, drawable.getMinimumWidth(),
//              drawable.getMinimumHeight());
//          holder.tv_clock.setCompoundDrawables(drawable2, null, drawable, null);
//          holder.tv_clock.setTag(true);
//        }
//
//        if (Tools.isNotEmpty(mHabitMusic.playtime)
//            && (mHabitMusic.playtime.contains("已执行") || mHabitMusic.playtime
//                .contains("已完成"))) {
//          holder.bg.setText("已执行");
//          holder.bg.setTextSize(TypedValue.COMPLEX_UNIT_SP, 11);
////          holder.img_palyorpause.setClickable(false);
////          holder.img_palyorpause.setBackgroundResource(R.drawable.play_gray);
//
//          Drawable drawable = mContext.getResources().getDrawable(
//              R.drawable.edit_habit);
//          drawable.setBounds(0, 0, drawable.getMinimumWidth(),
//              drawable.getMinimumHeight());
//          holder.tv_clock.setCompoundDrawables(drawable2, null, drawable, null);
//          holder.tv_clock.setTag(false);
//        }
//
////        holder.img_palyorpause.setOnClickListener(new View.OnClickListener() {
////          @Override
////          public void onClick(View v) {
////            ImHelper mImHelper = MyTeacherApp.getInstance().getImHelper();
////            if (mImHelper != null && mImHelper.isLogin()) {
////              if (Tools.isNotEmpty(mHabitMusic.playstatus)
////                  && mHabitMusic.playstatus.contains("playing")) {
////                JSONObject jsonObject = new JSONObject();
////                try {
////                  jsonObject.put("code", "app");
////                  jsonObject.put("act", "habit_pause");
////                  jsonObject.put("data", "");
////                  mImHelper.send(jsonObject.toString());
////                } catch (JSONException e) {
////                  e.printStackTrace();
////                }
////              } else {
////                JSONObject jsonObject = new JSONObject();
////                try {
////                  jsonObject.put("code", "app");
////                  jsonObject.put("act", "habit_start");
////                  jsonObject.put("data", "");
////                  mImHelper.send(jsonObject.toString());
////                } catch (JSONException e) {
////                  e.printStackTrace();
////                }
////              }
////            }
////          }
////        });
//      }
//    } else {
////      holder.img_palyorpause.setClickable(false);
////      holder.img_palyorpause.setBackgroundResource(R.drawable.play_gray);
//    }
//
//    return convertView;
//  }
//
//  private static class ViewHolder {
//    ProgressBar pb_day;
//    TextView tv_label;// 21tian
//    TextView tv_insistdays; // 已堅持
//    TextView tv_morningsong; // 清晨刷牙歌
//    TextView tv_clock;
//    Button bg; // "已完成"
//    View slayout;
//   ImageView img; //, img_palyorpause;
//  }
//
//}
